/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.model.service;

import com.model.domain.persona.Cargo;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Rdelacruz
 */
public class CargoService 
extends AbstractService
{   
    
    public Cargo findByCodigo(Connection con, String codigo) throws SQLException {
                
        Statement st = null;
        try {            
            
            st = con.createStatement();
            ResultSet rs = st.executeQuery("select * from Cargo where Cargo='"+codigo+"'");                       
            if(rs.next()) {
                Cargo c = new Cargo();
                c.setCodigo(rs.getString("Cargo"));
                c.setNombre(rs.getString("NomCargo"));
                c.setAbreviatura(rs.getString("AbrCargo"));
                return c;
            }
        }
        finally {
            if(st!=null) st.close();                        
        }
        return null;
    }
    
        
    public List<Cargo> findAll(Connection con) throws SQLException {
        List<Cargo> lista = new ArrayList<Cargo>();
                
        Statement st = null;
        try {            
            
            st = con.createStatement();
            ResultSet rs = st.executeQuery("select * from Cargo");
                       
            while(rs.next()) {                
                Cargo c = new Cargo();
                c.setCodigo(rs.getString("Cargo"));
                c.setNombre(rs.getString("NomCargo"));
                c.setAbreviatura(rs.getString("AbrCargo"));
                lista.add(c);
            }
        }
        finally {
            if(st!=null) st.close();                        
        }
        return lista;
    }

    public List<Cargo> findParaExportar(Connection con) throws SQLException {
        return findAll(con);
    }
    
    
    
}
